package com.huluobo.a2307douyindemo.mine

import androidx.lifecycle.MutableLiveData
import com.huluobo.lib_base.bean.VideoBean
import com.huluobo.lib_base.db.DouYinDatabase
import com.huluobo.lib_base.mvvm.BaseViewModel
import com.huluobo.lib_base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 *  Created by LC on 2025/9/18.
 */
@HiltViewModel
class MineViewModel @Inject constructor(private val db: DouYinDatabase, private val apiService: ApiService) :
    BaseViewModel() {
    val queryCollectVideosSuccess by lazy { MutableLiveData<List<VideoBean>>() }
    fun queryCollectVideos() {
        executeDb(
            { db.getVideoDao().queryVideoInfo() },
            queryCollectVideosSuccess::postValue
        )
    }

    val getLikeVideosSuccess by lazy { MutableLiveData<List<VideoBean>>() }
    fun getLikeVideos() {
        executeNetwork(
            { apiService.getLikeVideos() },
            getLikeVideosSuccess::postValue
        )
    }

    val unLikeSuccess by lazy { MutableLiveData<String>() }
    fun unLikeVideo(videoId: Int) {
        executeNetwork(
            { apiService.unLikeVideo(videoId) },
            unLikeSuccess::postValue
        )
    }

    val deleteCollectVideoSuccess by lazy { MutableLiveData<String>() }
    fun deleteCollect(videoBean: VideoBean) {
        executeDb(
            {
                db.getVideoDao().deleteVideoInfo(videoBean)
                "删除收藏"
            },
            deleteCollectVideoSuccess::postValue
        )
    }
}